<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('配件管理列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="partsType" name="partsType">
                    <input type="hidden" id="parentId" name="parentId">
                    <input type="hidden" id="isHotPush" name="isHotPush" value="1">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>厂家名称：</label>
                                <input type="text" name="factoryName"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="partsName"/>
                            </li>
                            <!--<li>
                                <label style="width: 120px;">大区是否上架：</label>
                                <select name="isShowProvince" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px;">配件店是否上架：</label>
                                <select name="isShowCity" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px;">维修店是否上架：</label>
                                <select name="isShowWorker" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: layout-latest-js" />
    <th:block th:include="include :: ztree-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:parts:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:parts:remove')}]];
        var isTodayHotDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isNewPushDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isGoodChoiceDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isHotPushDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isPostDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowProvinceDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowCityDatas = [[${@dict.getType('zsyh_yesno')}]];
        var isShowWorkerDatas = [[${@dict.getType('zsyh_yesno')}]];
        var partsClassificationDatas = [[${@dict.getType('parts_class')}]];
        var isViewAttrsDatas = [[${@dict.getType('zsyh_yesno')}]];
        var partsHasGrantDatas = [[${@dict.getType('zsyh_yesno')}]];
        var partsDistinguishDatas = [[${@dict.getType('parts_brand')}]];
        var partsRebateTypeDatas = [[${@dict.getType('parts_rebate')}]];
        var prefix = ctx + "zsyh/parts";

        $(function() {
            queryPartsList();
        });

        function queryPartsList() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                pagination: false,
                modalName: "产品管理",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '产品Id',
                    visible: false
                },
                /*{
                    field: 'factoryId',
                    title: '厂家信息Id'
                },*/
                    {
                        field: 'partsImages',
                        title: '产品主图',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                {
                    field: 'partsName',
                    align: 'center',
                    title: '产品名称'
                },
                {
                    field: 'partsNumber',
                    align: 'center',
                    title: '产品编码'
                },
                    /*{
                        field: 'partsUnit',
                        align: 'center',
                        title: '产品单位'
                    },*/
                {
                    field: 'partsTypeName',
                    align: 'center',
                    title: '产品分类'
                }, {
                    field: 'factoryName',
                        align: 'center',
                    title: '厂家名称'
                },
                /*{
                    field: 'partsBrand',
                    title: '配件品牌'
                },*/
                /*{
                    field: 'partsDetails',
                    title: '配件描述'
                },*/

                /*{
                    field: 'partsRemarks',
                    title: '配件详细信息'
                },*/
                /*{
                    field: 'isTodayHot',
                    title: '是否今日热卖',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isTodayHotDatas, value);
                    }
                },
                {
                    field: 'isNewPush',
                    title: '是否新品推荐',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isNewPushDatas, value);
                    }
                },
                {
                    field: 'isGoodChoice',
                    title: '是否好物优选',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isGoodChoiceDatas, value);
                    }
                },*/
                {
                    field: 'isHotPush',
                    title: '是否热门推荐',
                    align: 'center',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isHotPushDatas, value);
                    }
                },
                /*{
                    field: 'isPost',
                    title: '是否包邮',
                    align: 'center',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPostDatas, value);
                    }
                },*/
                /*{
                    field: 'partsQuantity',
                    title: '订购最低数量'
                },*/

                /*{
                    field: 'isShowProvince',
                    title: '省级是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowProvinceDatas, value);
                    }
                },*/
                /*{
                    field: 'isShowCity',
                    title: '市县级是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowCityDatas, value);
                    }
                },*/
                /*{
                    field: 'isShowWorker',
                    title: '维修师傅是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowWorkerDatas, value);
                    }
                },*/
                /*{
                    field: 'partsClassification',
                    title: '分类 1配件 2整机',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsClassificationDatas, value);
                    }
                },*/

                /*{
                    field: 'partsLogo',
                    title: '配件图标'
                },*/
                /*{
                    field: 'partsDamageDetails',
                    title: '补助金使用方法'
                },
                {
                    field: 'partsTaobaourl',
                    title: '淘宝连接'
                },*/
                /*{
                    field: 'partsVideourl',
                    title: '主图视频'
                },*/
                /*{
                    field: 'isViewAttrs',
                    title: '是否显示属性信息',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isViewAttrsDatas, value);
                    }
                },*/
                /*{
                    field: 'partsConditions',
                    title: '赔付条件'
                },*/
                {
                    field: 'partsHasGrant',
                    title: '是否有补助金',
                    align: 'center',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsHasGrantDatas, value);
                    }
                },
                {
                    field: 'partsDistinguish',
                    title: '产品商标',
                    align: 'center',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsDistinguishDatas, value);
                    }
                },
                    {
                        field: 'partsSort',
                        title: '排序',
                        align: 'center',
                        sortable:true
                    },
                /*{
                    field: 'partsRebateType',
                    title: '返点方式 1差额 2百分比',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsRebateTypeDatas, value);
                    }
                },*/
                /*{
                    field: 'partsAttention',
                    title: '注意事项'
                },
                {
                    field: 'partsInstructions',
                    title: '使用说明'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="moveTop(\'' + row.id + '\')"><i class="fa fa-edit"></i>置顶</a> ');
                        if(index !=0){
                            actions.push('<a class="btn btn-success btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="moveUp(\'' + row.id + '\',\''+index+'\')"><i class="fa fa-remove"></i>上移</a>');
                        }
                        actions.push('<a class="btn btn-warning btn-xs ' + removeFlag + '" style="margin-left: 3px;" href="javascript:void(0)" onclick="moveDown(\'' + row.id + '\',\''+index+'\')"><i class="fa fa-remove"></i>下移</a>');
                        actions.push('<a style="margin-left: 3px" class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看产品规格</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        };

        function batchUpdate(id) {
            $.modal.openTab("批量添加规格", ctx+"zsyh/partsattribute/view/"+id,'800', '800');
        }

        function moveTop(id) {
            $.modal.confirm("确认要置顶该产品吗？", function() {
                $.operate.post(prefix + "/moveTop", { "id":id});
            })
        }

        function moveDown(id,index) {
            debugger;
            var otherIndex = Number(index)+1;
            var otherData = $("#bootstrap-table").bootstrapTable('getData')[otherIndex];
            if(otherData != undefined){
                var currentData = $("#bootstrap-table").bootstrapTable('getData')[index];
                var upId = otherData.id;
                $.modal.confirm("确认要移动该产品吗？", function() {
                    $.operate.post(prefix + "/moveUp", { "id":id,"otherId":upId,"partsSort":currentData.partsSort,"otherPartsSort":otherData.partsSort});
                })
            }else{
                $.modal.alertWarning("当前页中最后一个不能下移");
            }
        }

        function moveUp(id,index) {
            var otherData = $("#bootstrap-table").bootstrapTable('getData')[index-1];
            var currentData = $("#bootstrap-table").bootstrapTable('getData')[index];
            var upId = otherData.id;
            $.modal.confirm("确认要移动该产品吗？", function() {
                $.operate.post(prefix + "/moveUp", { "id":id,"otherId":upId,"partsSort":currentData.partsSort,"otherPartsSort":otherData.partsSort});
            })
        }

    </script>
</body>
</html>